#include "TextField.h"
#include "FreeTypeFont.h"
#include "Technique.h"
TextField::TextField(void)
{
}

TextField::~TextField(void)
{
}
int TextField::getTextSize()
{
	return mTextBuffer.length();
}
void TextField::clear()
{

}
void TextField::insertChar( int nIndex, wchar_t wChar )
{
	if (nIndex < 0 || nIndex >= getMaxLength())
	{
		return;
	}
	if (getTextSize()+1 >= getMaxLength())
	{
		return;
	}
	mTextBuffer.insert(mTextBuffer.begin()+nIndex,wChar);
}
void TextField::removeChar( int nIndex )
{
	if (nIndex <0 || nIndex >= getMaxLength())
	{
		return;
	}
	if (getTextSize()+1 >= getMaxLength())
	{
		return;
	}
	mTextBuffer.erase (mTextBuffer.begin()+nIndex);
}
void TextField::insertString( int nIndex, const wchar_t* pStr, int nCount)
{

}
void TextField::setText( wchar_t* wszText )
{
	std::wstring s(wszText);
	mTextBuffer = s;
}
void TextField::getTextCopy(wchar_t**)
{

}
void TextField::draw(SpriteBatch* spriteBatch)
{
	wchar_t* buff = const_cast<wchar_t*> ( mTextBuffer.c_str() );
	AffineTransform trans = nodeToWorldTransform();
	Point point = PointApplyAffineTransform(getPosition(),trans);
	if (spriteBatch != NULL)
	{
		spriteBatch->drawString(buff, point.x, point.y, 900,25,mColor);
	}
}
void TextField::onCharacter(KeyEventArgs& e)
{
	insertChar(getTextSize(),e.codepoint);
}
